//
//  CedarTableViewSectionMaker.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/3/20.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "CedarTableViewSectionMaker.h"

@implementation CedarDataSourceSection

@end

@implementation CedarTableViewSectionMaker

- (CedarTableViewSectionMaker *(^)(Class))cell {
    return ^CedarTableViewSectionMaker *(Class cell) {
        self.section.cell = cell;
        if (!self.section.identifier) {
            self.section.identifier = [self getIdentifier];
        }
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(NSArray *))data {
    return ^CedarTableViewSectionMaker *(NSArray * data) {
        self.section.data = data;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(AdapterBlock))adapter {
    return ^CedarTableViewSectionMaker *(AdapterBlock adapterBlock) {
        self.section.adapter = adapterBlock;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(CGFloat))height {
    return ^CedarTableViewSectionMaker *(CGFloat height) {
        self.section.staticHeight = height;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(void))autoHeight {
    return ^CedarTableViewSectionMaker * {
        self.section.isAutoHeight = YES;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(EventBlock))event {
    return ^CedarTableViewSectionMaker *(EventBlock event) {
        self.section.event = event;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(NSString *))headerTitle {
    return ^CedarTableViewSectionMaker *(NSString * title) {
        self.section.headerTitle = title;
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(NSString *))footerTitle {
    return ^CedarTableViewSectionMaker *(NSString * title) {
        self.section.footerTitle = title;
        return self;
    };
}

- (CedarDataSourceSection *)section {
    if (! _section) {
        _section = [[CedarDataSourceSection alloc] init];
    }
    return _section;
}

- (CedarTableViewSectionMaker * (^)(UIView * (^)(void)))headerView {
    return ^CedarTableViewSectionMaker *(UIView * (^view)(void)) {
        self.section.headerView = view();
        return self;
    };
}

- (CedarTableViewSectionMaker * (^)(UIView * (^)(void)))footerView {
    return ^CedarTableViewSectionMaker *(UIView * (^view)(void)) {
        self.section.footerView = view();
        return self;
    };
}

- (NSString *)getIdentifier {
    CFUUIDRef uuidRef = CFUUIDCreate(NULL);
    CFStringRef uuidStrRef = CFUUIDCreateString(NULL, uuidRef);
    CFRelease(uuidRef);
    NSString * retStr = (__bridge NSString *) uuidStrRef;
    CFRelease(uuidStrRef);
    return retStr;
}

@end
